package com.FileDemo;

import java.io.*;

/*
 * 字符输出流
 * */
public class CoversionStreamDemo {
    public static void main(String[] args) throws IOException {
//        OutputStreamWriter(OutputStream out)
//        创建一个使用默认字符编码的OutputStreamWriter
//        OutputStreamWriter(OutputStream out, String charsetName)
//        创建一个使用命名字符集的OutputStreamWriter

        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("fos.txt"),"UTF-8");//默认是utf-8字符集
        osw.write("中国");
        osw.close();

//        InputStreamReader(InputStream in)
//        创建一个使用默认字符集的InputStreamReader。
//        InputStreamReader(InputStream in, String charsetName)
//        创建一个使用命名字符集的InputStreamReader。
        InputStreamReader ins = new InputStreamReader(new FileInputStream("fos.txt"),"UTF-8");

//        byte[] bytes = new byte[1024];
        char[] cbuf = new char[1024];
        int ch;
        while ((ch = ins.read(cbuf)) != -1) {
            System.out.print(cbuf);
        }
        ins.close();

    }
}
